﻿using BCCommon;
using BCDto.TMS.TrainingSite.TrainingSiteConfig;
using BCService.TMS.TrainingSite.TrainingSiteConfig;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.TrainingSite
{
    /// <summary>
    /// 培训点配置
    /// </summary>
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class TrainingSiteConfigController : ManagementBaseController
    {
        private readonly ITrainingSiteConfigService trainingSiteConfigService;

        public TrainingSiteConfigController(ITrainingSiteConfigService trainingSiteConfigService)
        {
            this.trainingSiteConfigService = trainingSiteConfigService;
        }

        #region POST 添加 
        /// <summary>
        /// 添加培训点配置
        /// </summary>
        /// <param name="dto">培训点配置请求信息模型</param>
        /// <returns></returns>
        [Log("添加培训点配置")]
        [HttpPost]
        [ProducesResponseType(typeof(TrainingSiteConfigDto), 200)]
        public IActionResult Post([FromBody] TrainingSiteConfigRequestDto dto)
        {
            var result = trainingSiteConfigService.Add(this.Admin, dto);
            return Ok(result);
        }

        #endregion

        #region PUT 修改 
        /// <summary>
        /// 修改培训点配置
        /// </summary>
        /// <param name="trainingSiteConfigId">培训点配置ID</param>
        /// <param name="dto">培训点配置修改信息模型</param>
        /// <returns></returns>
        [Log("修改培训点配置")]
        [HttpPut("{training_site_config_id}")]
        [ProducesResponseType(typeof(TrainingSiteConfigDto), 200)]
        public IActionResult Put([FromRoute(Name = "training_site_config_id")]long trainingSiteConfigId,
            [FromBody] TrainingSiteConfigPutDto dto)
        {
            var a = Ok(trainingSiteConfigService.Update(this.Admin, trainingSiteConfigId, dto));
            return a;
        }
        #endregion

        #region 删除 
        /// <summary>
        /// 删除培训点配置
        /// </summary>
        /// <param name="trainingSiteConfigId">培训点配置ID</param>
        /// <returns></returns>
        [Log("删除培训点配置")]
        [HttpDelete("{training_site_config_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "training_site_config_id")] long trainingSiteConfigId)
        {
            this.trainingSiteConfigService.Delete(this.Admin, trainingSiteConfigId);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条培训点配置
        /// </summary>
        /// <param name="trainingSiteConfigId">培训点配置ID</param>
        /// <returns></returns>
        [HttpGet("{training_site_config_id}")]
        [ProducesResponseType(typeof(TrainingSiteConfigDto), 200)]
        public IActionResult Get([FromRoute(Name = "training_site_config_id")] long trainingSiteConfigId)
        {
            var result = this.trainingSiteConfigService.GetById(trainingSiteConfigId);
            return this.Ok(result);
        }
        #endregion

        #region Query 
        /// <summary>
        /// 获取培训点配置
        /// </summary>
        /// <param name="trainingSiteName">培训点名称</param>
        /// <param name="provinceCode">省编码</param>
        /// <param name="cityCode">市编码</param>
        /// <param name="countyCode">区县编码</param>
        /// <param name="phone">联系电话</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<TrainingSiteConfigDto>), 200)]
        public IActionResult Query([FromQuery(Name = "training_site_name")]string trainingSiteName,
            [FromQuery(Name = "province_code")]string provinceCode,
            [FromQuery(Name = "city_code")]string cityCode,
            [FromQuery(Name = "county_code")]string countyCode,
            [FromQuery(Name = "phone")]string phone,
            [FromQuery(Name = "page_index")] int pageIndex = 1, 
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            var result = trainingSiteConfigService.Query(this.Admin, trainingSiteName, provinceCode, cityCode, countyCode, phone, pageIndex, pageSize);
            return this.Ok(result);
        }
        #endregion

        /// <summary>
        /// 获取培训点配置列表
        /// </summary>
        /// <param name="countyCode">区县编码</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<TrainingSiteConfigDto>), 200)]
        public IActionResult List([FromQuery(Name = "county_code")]string countyCode)
        {
            long? agentRecordId = null;
            if (this.Admin.AgentRecord != null)
            {
                agentRecordId = this.Admin.AgentRecord.AgentRecordId;
            }
            var result = this.trainingSiteConfigService.GetList(agentRecordId, countyCode);
            return this.Ok(result);
        }
    }
}
